package hihocoder;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class Forbidden {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		int M=scanner.nextInt();
		scanner.nextLine();
		ArrayList<String> list=new ArrayList<>(N);
		boolean allow[]=new boolean[N];
		for (int i = 0; i < N; i++) {
			String string=scanner.nextLine();
			String[] strings=string.split(" ");
			list.add(strings[1]);
			if(strings[0]!="deny"){
				allow[i]=true;
			}
		}
		for (int i = 0; i < M; i++) {
			String string=scanner.nextLine();
			int result=-1;
			result=match(string,list,allow);
			if(allow[result]==false){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
		}
	}

	private static int match(String string, ArrayList<String> list, boolean[] allow) {
		int i=0;
		for (String string2 : list) {
			if (match(string2, string)) {
				return i;
			}
			i++;
		}
		return -1;
	}

	/**
	 * 
	 * @param string2 规则IP
	 * @param string 访问的IP
	 * @return
	 */
	private static boolean match(String string2, String string) {
		int index=string2.lastIndexOf('/');
		if(index!=-1){//规则是掩码
			int mask=Integer.parseInt(string2.substring(index+1));
			string2=string2.substring(0, index);
			while (mask>=8) {
				int indx1=string2.indexOf('.');
				int indx2=string.indexOf('.');
				if(string2.substring(0, indx1).equals(string.substring(0, indx2))){
					return false;
				}
				string2=string2.substring(indx1+1);
				string=string.substring(indx2+1);
				mask-=8;
			}
			//匹配最高mask位
			String num1=getBinaryStr(string);
			String num2=getBinaryStr(string2);
			for (int i = 0; i < mask; i++) {
				if(num1.charAt(i)!=num2.charAt(i)){
					return false;
				}
			}
			return true;
		}else {
			return string2.equals(string);
		}
	}

	/**
	 * 获取string的二进制八位的数字表示
	 * @param string
	 * @return
	 */
	private static String getBinaryStr(String string) {
		Integer num=Integer.parseInt(string.substring(0, string.indexOf('.')));
		String numStr=Integer.toBinaryString(num);
		int diff=8-numStr.length();
		StringBuilder sBuilder=new StringBuilder();
		for (int i = 0; i < diff; i++) {
			sBuilder.append("0");
		}
		sBuilder.append(numStr);
		return sBuilder.toString();
	}

}
